package no.sachmuld.methodcombination.api.reflection;

import no.sachmuld.methodcombination.api.Direction;
import no.sachmuld.methodcombination.api.reflection.component.DelegatingMethodCombination;
import no.sachmuld.methodcombination.api.reflection.component.ContractCheckingMethodCombination;
import no.sachmuld.methodcombination.api.reflection.component.PrimaryMethodCombination;

import java.lang.reflect.Method;

/**
 *
 */
public class DesignByContract<R> extends DelegatingMethodCombination<Object, R> {

    @Override
    public DesignByContract<R> build(Class behaviourClass, Method targetMethod) {

        final Direction direction = Direction.BOTTOM_UP;

        final ContractCheckingMethodCombination<Object, R> contractChecking = new ContractCheckingMethodCombination<>(
                new PrimaryMethodCombination<Object, R>(direction));

        buildChildren(behaviourClass, targetMethod, contractChecking);

        executedBy(contractChecking);

        return this;

    }

}
